#!/usr/bin/env ruby
#
# Creates a new API page, with a skeleton.
#


class NewPage

  def main(args)
    args.each do |arg|
      create_page arg
    end
  end

  private

  # Print 's' to STDERR
  def e(s)
    STDERR.puts s
  end

  # Creates a new page name or name + '.php'
  def create_page(name)
    file = name + '.php' if name !~ /\.php$/
    if File.exist? file
      e file + ' already exists -- delete it first, then run this again'
      return
    end
    File.open file,'w' do |out|
      out.puts '<?php'
      out.puts ''
      out.puts '/*'
      out.puts '* TODO:Description'
      out.puts '*'
      out.puts '* INPUT: TODO'
      out.puts '* OUTPUT: TODO'
      out.puts '*/'
      out.puts ''
      out.puts 'include \'top.php\';'
      out.puts ''
      out.puts '// TODO: implementation'
      out.puts ''
      out.puts 'include \'done.php\';'
      out.puts ''
      out.puts '?>'
    end
  end
end
NewPage.new.main ARGV
